<template>
	<!-- 自提订单详情 -->
	<view style="padding-bottom: 100rpx;">
		<view class="head_1 bg-white flex-cb">
			<view class="head_div">
				<!-- <view class="address">贵州省贵阳市花果园金融街5号27楼2701号</view> -->
				<view class="name_people flex-cb">
					<view class="left">
						<view class="people">提货人</view>
						<text
							class="name_phone">{{goods.self_pick.user_nickname||goods.service.merchant_contact_person}}</text>
					</view>
					<view class="right"
						@click="$utils.callphone(goods.self_pick.user_phone||goods.service.merchant_contact_phone)">
						<view class="people">联系方式</view>
						<text
							class="name_phone">{{goods.self_pick.user_phone||goods.service.merchant_contact_phone}}</text>
					</view>
				</view>
			</view>
		</view>
		<view class="main">
			<view v-for="(item,index) in goods.goods" :key="index" class="item flex">
				<image :src="url+item.main_image" mode=""></image>
				<view class="text_div">
					<view class="name flex-cb ">
						<text class="text">{{item.title}}</text>
						<text class="tuikuan"
							v-if="index == isshow">{{goods.status==0?'待支付':goods.status==3?'已完成':goods.status==4?'退款中'
							:goods.status==5?'退款完成':goods.status==6?'已支付':goods.status==7?'待评价':goods.status==8?'已评价':
							goods.status==-1?'已取消':'已退款'}}</text>
					</view>
					<view class="pic flex justify-between">
						<text class="">原价:￥{{item.price}}</text>
						<text class="jifen">积分最多抵扣￥{{item.point_price||0}}</text>
					</view>
					<view class="numbar flex-cb">
						<text class="num_x">X{{item.number||0}}</text>
						<text>会员价:￥{{item.vip_price}}</text>
					</view>
				</view>
			</view>
			<view class="solid"></view>
			<view class="span">
				<view class="text_span " v-if="goods.discount_method==1">积分抵扣：￥{{goods.amount-goods.point_amount||0}}
				</view>
				<view class="text_span">商品数量：{{num}}</view>
				<view class="text_span">
					总价：￥{{goods.discount_method==0?goods.amount:goods.discount_method==1?goods.point_amount:goods.vip_amount}}
				</view>
			</view>
		</view>
		<view class="type bg-white" v-if="goods.service.items">
			<text>服务项目</text>
			<view class="type_list flex flex-wrap">
				<!-- :class="{item:index == istype}" -->
				<view v-for="(item,index) in goods.service.items" :key="index" class="flex-c" @click="istype =index">
					{{item.name}}
				</view>
			</view>
		</view>
		<view class="foot">
			<view class="ddxx">订单信息</view>
			<view class="solid"></view>
			<view class="span_div flex-cb">
				<view class="left">
					<view>订单编号</view>
					<view>自提时间</view>
					<view>下单时间</view>
					<view v-if="goods.pay_time">支付时间</view>
					<view>支付方式</view>
					<view v-if="goods.write_off_time">核销时间</view>
					<view>核销</view>
				</view>
				<view class="right">
					<view>{{goods.order_no}}</view>
					<view>{{goods.self_pick.user_self_pick_time}}</view>	
					<view>{{goods.created_at}}</view>
					<view v-if="goods.pay_time">{{goods.pay_time}}</view>
					<view>微信支付</view>
					<view v-if="goods.write_off_time">{{goods.write_off_time}}</view>
					<view>{{goods.is_write_off == 0 ? '未核销' : '已核销'}}</view>
				</view>
			</view>
		</view>
		<view class="div">
			<!-- 退款信息 -->
			<!-- <view class="foot foot2" v-if="goods.status ==4||goods.status==5||goods.status ==-2">
				<view class="ddxx">退款信息</view>
				<view class="solid"></view>
				<view class="span_div flex-cb">
					<view class="left">
						<view>退款金额</view>
						<view>退款时间</view>
						<view>退款类型</view>
						<view>{{goods.refund.status == 0?'退款':'拒绝'}}原因</view>
						<view v-if="goods.refund">退款截图</view>
					</view>
					<view class="right">
						<view>￥{{goods.refund.refund_amount}}</view>
						<view>{{goods.refund.created_at}}</view>
						<view >{{goods.refund.refund_type_id==3?'协商退款':'部分退款'}}</view>
						<view>{{goods.refund.status == 0?goods.refund.refund_instruction:goods.refund.reject_reason}}</view>
						<view v-if="goods.refund" class="cuIcon-right" @click="$utils.lookimg(url+goods.refund.image)"></view>
					</view>
				</view>
			</view> -->
			<!-- 拒绝退款弹窗 -->
			<!-- <view class="modal_view foot_model flex-c" v-if="index == 2" >
				<view class="modal_div" >
					<view class="title">拒绝原因</view>
					<view class="name">
						<textarea value="" placeholder="请填写拒绝原因" v-model="text" />
					</view>
					<view class="button_min flex-cb">
						<view class="left" @click="index=0">取消</view>
						<view class="center"></view>
						<view class="right" @click="yes">确定</view>
					</view>
				</view>
			</view> -->
		</view>
		<view class="bottom bg-white flex align-center justify-end" :style="{paddingBottom:iphone/2 + 'rpx'}" v-if="goods.is_write_off == 0">
			<view class="button button1" @click="handleCode" v-if="sancode">扫描二维码</view>
			<view class="button button1" @click="handleqrue" v-else>确认提货</view>
			<!-- <view class="button button1" @click="TYTK" v-if="goods.status == 4">同意退款</view> -->
			<!-- <view class="button button2" @click="index = 2" v-if="goods.status == 4">拒绝退款</view> -->
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				index: 0,
				isshow: 0,
				iphone: '',
				text: '',
				order_id: null,
				goods: {},
				num: null,
				sancode: 1, //扫描二维码是否显示
				url: '',
			};
		},
		onLoad(option) {
			if (uni.getStorageSync('access_token') == '') {
				this.$utils.isgologin()
			} else {
				if (option.q) {
					this.geturldata(option.q)
					this.getgoods(this.order_id)

				} else {
					this.order_id = option.id
					this.getgoods(this.order_id)
				}

			}
			if (option.id == 0) {
				this.isshow = 1
			}
			this.url = this.$base
			this.iphone = getApp().globalData.iphone
		},
		onPullDownRefresh() {
			this.getgoods(this.order_id)
		},
		methods: {
			handleNo() {
				this.index = 1
			},
			TYTK() { //同意退款
				let _this = this
				uni.showModal({
					title: '提示',
					content: '是否同意退款',
					success(res) {
						if (res.confirm) {
							_this.$api.efund_orders_agree({}, _this.order_id, 1).then(res => {
								if (res.code == 200001) {
									_this.getgoods(this.order_id)
								}
							})
						}
					}
				})
			},
			yes() { //拒绝退款
				if (this.text == '') {
					uni.showToast({
						icon: "none",
						title: '请输入拒绝理由'
					})
				}
				this.$api.efund_orders({
					reject_reason: this.text
				}, this.order_id, 1).then(res => {
					if (res.code == 200001) {
						this.getgoods(this.order_id)
						this.index = 0
					}
				})
			},
			GetRequest(url) {
				let theRequest = new Object();
				if (url.indexOf("?") != -1) {
					let str = url.substr(1);
					let strs = str.split("&");
					for (var i = 0; i < strs.length; i++) {
						theRequest[strs[i].split("=")[0]] = unescape(strs[i].split("=")[1]);
					}
				}
				return theRequest;
			},
			handleqrue() {
				this.$api.write_off({}, this.order_id, 1).then(res => {
					if (res.code == 200001) {
						this.getgoods(this.order_id)
					}
				})
			},
			handleCode() {
				// 扫码
				// 允许从相机和相册扫码
				uni.scanCode({
					scanType: ["qrCode"],
					success: (res) => {
						if (res.result) {
							const val = res.result;
							this.geturldata(val)
						} else {
							console.log('请重新扫描');
							return false;
						}
					},
					fail: (res) => {
						console.log('未识别到二维码');
					}
				})
			},
			getgoods(id) {
				this.$api.orders_details({}, id, 1).then(res => {
					console.log(res);
					this.goods = res.data
					for (let i = 0; i < res.data.goods.length; i++) {
						this.num += this.goods.goods[i].number
					}
				})
			},
			geturldata(url) {
				console.log(url);
				const q = decodeURIComponent(url) // 获取到二维码原始链接内容
				let t = JSON.parse(JSON.stringify(q))
				var Request = new Object();
				Request = this.GetRequest(t);
				this.order_id = Request.id
				this.sancode = 0
				this.getgoods(this.order_id)
				console.log(Request, Request['ttps://guizhouchenxun.com/mini/write/?indexs']);
			}
		}
	}
</script>

<style lang="scss">
	.head_1 {
		width: 706rpx;
		height: auto;
		border-radius: 20rpx;
		margin: 10rpx auto;
		padding: 30rpx 20rpx;

		.head_div {
			height: 100%;

			.name_people {
				height: 84rpx;
				margin-top: 17rpx;

				.left {
					width: 220rpx;
					border-right: solid 1rpx #999;
				}

				.right {
					margin-left: 28rpx;
				}

				.people {
					font-size: 24rpx;
					color: #999;
					height: 33rpx;
				}

				.name_phone {
					font-size: 30rpx;
					font-weight: bold;
					color: #333;
					height: 42rpx;
				}
			}
		}

		.address {
			width: 442rpx;
			height: 88rpx;
			font-size: 28rpx;
			font-family: PingFang SC-Bold, PingFang SC;
			font-weight: bold;
			color: #333333;
			line-height: 48rpx;
		}

		map {
			width: 172rpx;
			height: 172rpx;
			border-radius: 10rpx;
		}
	}

	.main {
		width: 706rpx;
		height: auto;
		background: #FFFFFF;
		border-radius: 20rpx;
		padding: 26rpx 0;
		margin: auto;

		.item {
			margin-bottom: 61rpx;
			padding: 0 20rpx 0 27rpx;

			image {
				width: 136rpx;
				height: 136rpx;
			}

			.text_div {
				flex: 1;
				margin-left: 19rpx;
				font-size: 28rpx;
				color: #333333;

				.name {
					height: 40rpx;

					.text {
						height: 40rpx;
						font-weight: bold;
					}

					.tuikuan {
						font-size: 30rpx;
						font-weight: 500;
						color: #1CD699;
					}
				}

				.pic {
					height: 40rpx;
					margin-top: 20rpx;

					.jifen {
						color: #FF6F10;
						font-size: 24rpx;
					}
				}

				.numbar {
					text {
						height: 33rpx;
						font-size: 24rpx;
						font-family: PingFang SC-Bold, PingFang SC;
						font-weight: bold;
						color: #FF2E2E;
					}

					.num_x {
						font-size: 30rpx;
						font-weight: 500;
						color: #999;
					}
				}
			}
		}

		.span {
			padding-top: 24rpx;

			.text_span {
				font-size: 30rpx;
				color: #666;
				padding: 0 25rpx;
				margin-bottom: 20rpx;
			}
		}

	}

	.type {
		width: 706rpx;
		height: auto;
		border-radius: 10rpx;
		margin: 10rpx auto;
		padding: 30rpx 0 24rpx 24rpx;

		text {
			font-size: 30rpx;
			font-weight: bold;
			color: #2F2F2F;
		}

		.type_list {
			margin-top: 41rpx;

			view {
				width: 121rpx;
				height: 60rpx;
				background: #F2F2F2;
				border-radius: 10rpx;
				font-size: 28rpx;
				color: #999999;
				margin-right: 16rpx;
			}

			.item {
				color: #fff;
				background: #1CD699;
			}
		}
	}

	.foot {
		width: 706rpx;
		background: #FFFFFF;
		border-radius: 20rpx;
		margin: 10rpx auto;

		.ddxx {
			height: 90rpx;
			font-size: 30rpx;
			color: #333333;
			font-weight: bold;
			padding-left: 28rpx;
			padding-top: 20rpx;
		}

		.span_div {
			padding: 0 28rpx;
			margin-top: 29rpx;

			.left,
			.right {
				width: 120rpx;
				font-size: 30rpx;
				color: #666;
				line-height: 70rpx;
			}

			.right {
				width: 360rpx;
				text-align: right;
			}
		}
	}

	.bottom {
		width: 100%;
		min-height: 107rpx;
		padding-top: 24rpx;
		padding-right: 29rpx;
		position: fixed;
		bottom: 0;
		left: 0;

		.button {
			width: 210rpx;
			height: 70rpx;
			margin-left: 12rpx;
			background: #FF6F10;
			border-radius: 70rpx;
			font-size: 30rpx;
			line-height: 70rpx;
			text-align: center;
			color: #fff;
		}

		.button1 {
			background: #1CD699;
		}

		.button2 {
			background: #FF2E2E;
		}
	}

	.solid {
		width: 690rpx;
		margin: 0 8rpx;
	}

	.foot_model {
		.modal_div {
			width: 532rpx;
			height: auto;
			background: #F3F3F3;
			border-radius: 10rpx;
			padding-bottom: 117rpx;
			position: relative;

			.title {
				color: #070707;
				font-size: 26rpx;
				font-weight: 500;
				margin-top: 32rpx;
				margin-bottom: 52rpx;
				text-align: center;
			}

			.name {
				width: 472rpx;
				height: 219rpx;
				background: #F3F3F3;
				border-radius: 10rpx;
				border: 1rpx solid #DADADA;
				margin: auto;
				padding: 20rpx;
				color: #B5B2B5;
				font-size: 24rpx;

			}

			.button_min {
				position: absolute;
				bottom: 0;
				left: 0;
				width: 100%;
				height: 78rpx;
				border-top: solid 1rpx #DADADA;

				.center {
					width: 1rpx;
					height: 66rpx;
					background: #DADADA;
					border-radius: 1rpx;
				}

				.left,
				.right {
					flex: 1;
					font-size: 26rpx;
					text-align: center;
				}

				.right {
					color: #1CD699;
				}
			}
		}

	}

	.div {
		.foot {
			width: 706rpx;
			height: auto;
			background: #FFFFFF;
			border-radius: 20rpx;
			margin: 10rpx auto;

			.ddxx {
				height: 90rpx;
				font-size: 30rpx;
				color: #333333;
				font-weight: bold;
				padding-left: 28rpx;
				padding-top: 20rpx;
			}

			.span_div {
				padding: 0 28rpx;
				margin-top: 29rpx;

				.left,
				.right {
					width: 120rpx;
					font-size: 30rpx;
					color: #666;
					line-height: 70rpx;
				}

				.right {
					width: 360rpx;
					text-align: right;
				}
			}
		}

		.foot2 {
			margin-bottom: 170rpx;
		}

		.bottom {
			width: 100%;
			min-height: 107rpx;
			padding-right: 29rpx;
			padding-top: 24rpx;
			position: fixed;
			bottom: 0;
			left: 0;

			.button {
				width: 210rpx;
				height: 70rpx;
				margin-left: 12rpx;
				background: #FF6F10;
				border-radius: 70rpx;
				font-size: 30rpx;
				line-height: 70rpx;
				text-align: center;
				color: #fff;
			}

			.button1 {
				background: #1CD699;
			}

			.button2 {
				background: #FF2E2E;
			}
		}

		.solid {
			width: 690rpx;
			margin: 0 8rpx;
		}

		.foot_model {
			.modal_div {
				width: 532rpx;
				height: auto;
				background: #F3F3F3;
				border-radius: 10rpx;
				padding-bottom: 117rpx;
				position: relative;

				.title {
					color: #070707;
					font-size: 26rpx;
					font-weight: 500;
					margin-top: 32rpx;
					margin-bottom: 52rpx;
					text-align: center;
				}

				.name {
					width: 472rpx;
					height: 219rpx;
					background: #F3F3F3;
					border-radius: 10rpx;
					border: 1rpx solid #DADADA;
					overflow: hidden;
					margin: auto;
					padding: 20rpx;
					color: #B5B2B5;
					font-size: 24rpx;

					textarea {
						width: 100%;
						height: 100%;
					}

				}

				.button_min {
					position: absolute;
					bottom: 0;
					left: 0;
					width: 100%;
					height: 78rpx;
					border-top: solid 1rpx #DADADA;

					.center {
						width: 1rpx;
						height: 66rpx;
						background: #DADADA;
						border-radius: 1rpx;
					}

					.left,
					.right {
						flex: 1;
						font-size: 26rpx;
						text-align: center;
					}

					.right {
						color: #1CD699;
					}
				}
			}

		}
	}
</style>